#ifndef _SPI_TR700_HDR_H_
#define _SPI_TR700_HDR_H_



/**********************************************************
命令类型
**********************************************************/
#define CMD_UNDEFINE    (0x00)
#define CMD_ALIVE       (0x01) // 心跳、检验是否存在

#define CMD_GETENV_PRE  (0x02) // 获取环境变量
#define CMD_GETENV      (0x03) // 获取环境变量
#define CMD_SETENV      (0x04) // 设置环境变量
#define CMD_SAVEENV     (0x05) // 保存环境变量

// 通道（ch1、ch2）+功率（dBm）+模式（CW、270、1k、2k）
#define CMD_SETLS	(0x06) // 设置光源功率

// 设置光功率计参数：波长
#define CMD_OPM_W       (0x07) // 设置光功率计


// 通道
// 读取光功率计测试值：波长、模式、功率值
#define CMD_OPM_R       (0x08) // 读取光功率计
#define CMD_DBG         (0x09) // 调试模式
#define CMD_OPM_R_DBG         (0x0A) // 调试模式读取光功率计
#define CMD_OPM_W_DBG       (0x0b) // 设置光功率计

#define CMD_SETLS_DBG	(0x0c) // 设置光源功率
#define CMD_GETLS_DBG	(0x0d) // 设置光源功率

#define MIN_PACK_LEN (4)
#define END (0X00)


/**********************************************************
	命令格式
**********************************************************/

#define OFFSET_FLAG(x) (*((x) + 0))
#define OFFSET_ADDR(x) (*((x) + 1))
#define OFFSET_CMD(x)  (*((x) + 2))
#define OFFSET_LEN(x)  (*((x) + 3))

#define PTR_TXVAL(x) (((x) + 4))


struct tr700_common_tx {
#define CTX_F_SUCCESS  (0x00)
#define CTX_F_ERR      (0x01)
#define CTX_F_UNEMPTY  (0x02)
#define CTX_F_BUSY     (0x80)
	char flag;
	char addr;
	char cmd;
	char len;
}__attribute__ ((__packed__));





#define CRX_STATUS(x) (x->status)
#define CRX_CMD(x)    (x->cmd)
struct tr700_common_rx {
	char status;
	char cmd;
}__attribute__ ((__packed__));



#define LS_CW  (0x00)
#define LS_270 (0x01)
#define LS_1K  (0x02)
#define LS_2K  (0x03)
struct tr700_setls_tx {
	char ch;
	char mode;
	float dbm;
}__attribute__ ((__packed__));

struct tr700_setls_rx {
	struct tr700_common_rx crx;
}__attribute__ ((__packed__));

struct tr700_setls_dbg_tx {
	char   ch;
	char   mode;
	short  dac;
}__attribute__ ((__packed__));

struct tr700_setls_dbg_rx {
	struct tr700_common_rx crx;
}__attribute__ ((__packed__));

struct tr700_getls_dbg_rx {
	struct tr700_common_rx crx;
	char   			ch;
	char   			mode;
	short           adc;
	short           dac;
}__attribute__ ((__packed__));

struct tr700_getls_dbg {
	char   			ch;
	char   			mode;
	short           adc;
	short           dac;
}__attribute__ ((__packed__));


#define PRE_ENV_LEN (64)
struct tr700_setenv_tx {
	char env[PRE_ENV_LEN];
}__attribute__ ((__packed__));

struct tr700_setenv_rx {
	struct tr700_common_rx crx;
}__attribute__ ((__packed__));





struct tr700_getenv_tx {
	char env[PRE_ENV_LEN];
}__attribute__ ((__packed__));




struct tr700_getenv_rx {
	struct tr700_common_rx crx;
	char env[PRE_ENV_LEN];
}__attribute__ ((__packed__));


struct tr700_saveenv_rx {
	struct tr700_common_rx crx;
}__attribute__ ((__packed__));

#define OPM_R_CW  (0x00)
#define OPM_R_270 (0x01)
#define OPM_R_1K  (0x02)
#define OPM_R_2K  (0x03)
// struct xxx {

// }__attribute__ ((__packed__));


struct tr700_getopm_rx {
	struct tr700_common_rx crx;
	// unsigned short  adc;
	short           wave;
	float           dbm;
	unsigned int    mode;
	// int             lv;

}__attribute__ ((__packed__));

struct tr700_getopm {
	short           wave;
	float           dbm;
	unsigned int    mode;
};



struct tr700_dbg_tx {
	char           isdebug;
}__attribute__ ((__packed__));

struct tr700_dbg_rx {
	struct tr700_common_rx crx;
}__attribute__ ((__packed__));




struct tr700_opm_set_tx {
	char level;
}__attribute__ ((__packed__));

struct tr700_opm_set_rx {
	struct tr700_common_rx crx;
}__attribute__ ((__packed__));


struct tr700_getopm_dbg_rx {
	struct tr700_common_rx crx;
	int             level;
	short           adc;
	float           dbm;
}__attribute__ ((__packed__));


struct tr700_getopm_dbg {
	int             level;
	short           adc;
	float           dbm;
}__attribute__ ((__packed__));







#endif
